import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2023-01-04
 * Time: 19:05
 */
public class Solution2 {
    // https://leetcode.cn/problems/remove-duplicate-node-lcci/submissions/s
    public static ListNode removeDuplicateNodes(ListNode head) {
        if (head == null) {
            return null;
        }
        Set<Integer> set = new HashSet<>();
        ListNode cur = head;
        set.add(cur.val);
        while (cur.next != null) {
            if (!set.contains(cur.next.val)) {
                set.add(cur.next.val);
                cur = cur.next;
            } else {
                cur.next = cur.next.next;
            }
        }
        return head;
    }

    public static void main(String[] args) {
        List<Integer> list = new LinkedList<>();

    }
}
